package com.atguigu.jsp.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet(urlPatterns = "/Servlet02TestSessionScope")
public class Servlet02TestSessionScope extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、获取 HttpSession 对象，它代表当前会话
        HttpSession session = request.getSession();

        // 2、把数据存入会话域
        session.setAttribute("attrNameSession", "attrValueSession");

        // 3、重定向到 target.jsp
        response.sendRedirect(request.getContextPath() + "/pages/target.jsp");
    }
}
